package com.study.app.controller;

import com.study.app.entity.User;
import com.study.app.service.LockService;
import com.study.app.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author sjw
 * @className HomeController
 * @date 2020/11/18 10:18
 * @description: TODO
 */

@RestController

@RequestMapping("/home")
public class HomeController {

    @Autowired
    private UserService userService;

    @Autowired
    private LockService lockService;

    @GetMapping("/hello")
    public long hello() throws InterruptedException {
        System.out.println(Thread.currentThread().getId());
        Thread.sleep(1000);
        return System.currentTimeMillis();
    }

    @GetMapping("/users")
    public List<User> users(){
        return userService.users();
    }

    @GetMapping("/lock")
    public long lock(){
        return lockService.lock();
    }


    @PostMapping("/users/{second}")
    public Integer insert(@PathVariable Integer second) throws InterruptedException {
        return userService.insert(second);
    }
}
